#include <bits/stdc++.h>

const int INF = 2147483647;
const int NINF = -2147483648;
const int Mod = 998244353;
const int N = 1e1 + 10;

typedef long long ll;

using namespace std;

int n;
int ans;
int v[N];
struct Node {
    int s;
    int d[N];
    bool f[N];
} a[N];

void check() {
    for (int i = 1; i <= n; i++)
        if (v[i] == 1)
            for (int j = 1; j <= a[i].s; j++)
                if (v[a[i].d[j]] != a[i].f[j])
                    return;
    int sum = 0;
    for (int i = 1; i <= n; i++)
        sum += v[i];
    if (ans < sum)
        ans = sum;
}

void dfs(int x) {
    if (x > n) {
        check();
        return;
    }

    for (int i = 0; i <= 1; i++) {
        v[x] = i;
        dfs(x + 1);
    }
}

int main() {
	freopen("data.in", "r", stdin);
	freopen("myanswet.out", "w", stdout);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int cnt = 0;
        cin >> a[i].s;
        int m = a[i].s;
        while (m--)
            cin >> a[i].d[++cnt] >> a[i].f[cnt];
    }

    dfs(1);

    cout << ans;

    return 0;
}
